<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" type="text/css" href="/css/login.css"/>
    <link rel="stylesheet" type="text/css" href="/css/toastr.min.css"/>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/toastr.min.js"></script>

    <title>登录</title>
</head>
<body >
<div class="container">
    <div class="header"></div>
    <div class="main">
        <img class="login_img" src="/image/logo-name.png"/>
        <div class="login_div">
            <div class="wenzi">登&emsp;&nbsp;&nbsp;&nbsp;录</div>
            <input type="text" name="username" class="username" placeholder="请输入你的账号" />
            <input type="password" name="password" class="password" placeholder="请输入你的密码" />
            <input class="login " id="login"  type="button" value="登录"/>

        </div>
    </div>
    <div class="footer"></div>
</div>
</body>
<script type="text/javascript">
    var toastr;
    toastr.options = {
        closeButton: true,//显示关闭按钮
        debug: false,
        progressBar: true,//显示进度条
        positionClass: "toast-bottom-right",//位置
        onclick: null,//点击消息框自定义事件
        showDuration: "200",//显示动作时间
        hideDuration: "1000",//隐藏动作时间
        timeOut: "2000",//显示时间,0为永久显示
        extendedTimeOut: "1000",//鼠标移动过后显示显示时间
        showEasing: "swing",
        hideEasing: "linear",
        showMethod: "fadeIn",//显示方式
        hideMethod: "fadeOut"//隐藏方式
    };


    $("#login").click(function () {
        var username = $("[name=username]").val();
        var password = $("[name=password]").val();
        var reqdata={"sno":username,"password":password};
        $.ajax({
            url:"/user/login",//请求地址
            type:"POST",//请求方式
            contentType:"application/json;charset=UTF-8",
            data:JSON.stringify(reqdata),
            success:function (data) {//data表示是变量，会去接收服务器响应的值
                 if(data.result==true){
                   var role=data.roles.toString();
                   alert(role)
                     if(role=="学生"){
                         toastr.warning("学生没有权限登录系统")
                     }
                     else{
                         toastr.success("登录成功！")
                         console.info(data.roles);
                         window.location.href="http://localhost:8080/index"
                     }

                 }
                 if(data.result==false){
                     toastr.warning("账号或密码不正确")
                 }
            },//响应成功后的回调函数
            error:function () {
                toastr.error("出错啦")
            }
        })
    });
</script>
</html>